<?php
function validation1($usr, $clientpass, $serverpass, $dbc) {
//$clientpass and $serverpass correspond to a session!
	//require ('mysqli_connect.php');
	$q = "SELECT * FROM users where user='". mysqli_real_escape_string($dbc, $usr) ."'";
	$r = @mysqli_query ($dbc, $q);
	if($r) {
		$user = mysqli_fetch_array($r, MYSQLI_ASSOC);
		if($user) {
			if($clientpass == $serverpass)  {
				if( ( (int)$serverpass % (int)$user['logkey'] ) == 0) return $user;  //validation done (correct)
				else return 3; //user logged in, match with a session, but not his session (hack with a logged user)
			}
			else return 2; //user exist, but doesn't match with his actual session (hacks, not logged user)
		}
		else return 1; //invalid username (during an open session)
	}
	else return 4; // Database connection error
}

function select($r) {
	$select = array ();
	$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
	while($row) {
		$select[] = $row;
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
	}
	return $select;
}